import { App } from 'vue'
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { rootRoute, loginRoute, errorRoute } from './defaultRoute'
import permission from './permission'

const defaultRoutes: RouteRecordRaw[] = [rootRoute, loginRoute, errorRoute]

const router = createRouter({
  history: createWebHistory(),
  routes: defaultRoutes,
  scrollBehavior: () => ({ left: 0, top: 0 })
})

export const setupRouter = async (app: App) => {
  app.use(router)
  permission(router)
  await router.isReady()
}

export default router
